//
//  AboutViewController.m
//  Article
//
//  Created by Haricot_cpc17 on 16/4/27.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "AboutViewController.h"
#import <WXApi.h>

@interface AboutViewController ()

@end

@implementation AboutViewController{
    UIButton *_cancelbtn;//取消分享
    
    UIView   *_sheraview;//分享

    UIButton *_rightbtn;

}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = YES;
    self.tabBarController.tabBar.translucent = YES;
    [self.navigationController.navigationBar setBarTintColor:UIColorFromRGB(MYColor)];
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate =(id)self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"关于我们";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:18],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    [self.navigationController.navigationBar setBarTintColor:UIColorFromRGB(MYColor)];
    
    self.view.backgroundColor = UIColorFromRGB(0xffffff);
    
    
    if ([WXApi isWXAppInstalled]) {
        _rightbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
        [_rightbtn setTitle:@"分享" forState:UIControlStateNormal];
        [_rightbtn addTarget:self action:@selector(shareUIView) forControlEvents:UIControlEventTouchUpInside];
        [_rightbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rightbtn.titleLabel.font = [UIFont fontWithName:@"Heiti SC" size:15];
        UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithCustomView:_rightbtn];
        self.navigationItem.rightBarButtonItem = right;
        [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
    }
    //[self createUI];
    [self webview];
    // Do any additional setup after loading the view.
}
- (void)shareUIView{
    _rightbtn.userInteractionEnabled = NO;
    _cancelbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, WIDTH , HEIGHT)];
    
    _cancelbtn.alpha = 0;
    _cancelbtn.backgroundColor = [UIColor blackColor];
    
    [_cancelbtn addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_cancelbtn];
    
    
    [UIView animateWithDuration:0.3 animations:^{
        
        
        
        _cancelbtn.alpha = 0.6;
        
        _sheraview = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT - 180 * MYWIDTH, WIDTH, 180 * MYWIDTH)];
        _sheraview.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_sheraview];
        
        UILabel *titlelab = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, WIDTH/2, 20)];
        titlelab.text = @"分享到";
        titlelab.textColor = UIColorFromRGB(0x333333);
        titlelab.font = [UIFont systemFontOfSize:16];
        [_sheraview addSubview:titlelab];
        
        
        UIButton *wxbtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 35 * MYWIDTH, 50 * MYWIDTH, 50 * MYWIDTH)];
        wxbtn.tag = 1;
        [wxbtn setBackgroundImage:[UIImage imageNamed:@"weixin"] forState:UIControlStateNormal];
        [wxbtn addTarget:self action:@selector(sheraMessage:) forControlEvents:UIControlEventTouchUpInside];
        [_sheraview addSubview:wxbtn];
        
        UIButton *pyqbtn = [[UIButton alloc]initWithFrame:CGRectMake(90 * MYWIDTH, 35 * MYWIDTH, 50 * MYWIDTH, 50 * MYWIDTH)];
        pyqbtn.tag = 2;
        [pyqbtn setBackgroundImage:[UIImage imageNamed:@"pengyouquan"] forState:UIControlStateNormal];
        [pyqbtn addTarget:self action:@selector(sheraMessage:) forControlEvents:UIControlEventTouchUpInside];
        [_sheraview addSubview:pyqbtn];
        
        UILabel *wxlab = [[UILabel alloc]initWithFrame:CGRectMake(5, 85 * MYWIDTH, 70 * MYWIDTH, 20 * MYWIDTH)];
        wxlab.text = @"微信好友";
        wxlab.font = [UIFont systemFontOfSize:11];
        wxlab.textAlignment = NSTextAlignmentCenter;
        wxlab.textColor = UIColorFromRGB(0x666666);
        [_sheraview addSubview:wxlab];
        
        UILabel *pyqlab = [[UILabel alloc]initWithFrame:CGRectMake(80 * MYWIDTH, 85 * MYWIDTH, 70 * MYWIDTH, 20 * MYWIDTH)];
        pyqlab.text = @"朋友圈";
        pyqlab.font = [UIFont systemFontOfSize:12];
        pyqlab.textAlignment = NSTextAlignmentCenter;
        pyqlab.textColor = UIColorFromRGB(0x666666);
        [_sheraview addSubview:pyqlab];
    }];
}
-(void)sheraMessage:(UIButton *)btn{
    
    [self removeView];
    
    WXMediaMessage *messgae = [WXMediaMessage message];
    messgae.title = @"边广告边赚钱！三分钟讲解“拇指营销”如何收入轻松月入过万模式";
    [messgae setThumbImage:[UIImage imageNamed:@"关于我们分享图片"]];
    messgae.description = @"了解拇指营销--人人可为，终身仅仅投资298元、却能轻松实现月入过万的好项目！";
    WXWebpageObject *webpage = [WXWebpageObject object];

    webpage.webpageUrl = @"http://mp.weixin.qq.com/s?__biz=MzAxODQwMTYxMA==&mid=502752513&idx=1&sn=e6212db8bb98fbda13cff66fafdcb520&scene=1&srcid=0607KB0xxnsxbvR8S3FBpcpx&from=groupmessage&isappinstalled=0#wechat_redirect";
    
    messgae.mediaObject = webpage;
    
    SendMessageToWXReq *req = [[SendMessageToWXReq alloc]init];
    req.bText = NO;
    req.message = messgae;
    
    if (btn.tag == 1) {
        req.scene = WXSceneSession;
    }else if (btn.tag == 2){
        req.scene = WXSceneTimeline;
    }
    
    [WXApi sendReq:req];
    
}

-(void)removeView{
    _rightbtn.userInteractionEnabled = YES;
    [UIView animateWithDuration:0.5 animations:^{
        [_cancelbtn removeFromSuperview];
        [_sheraview removeFromSuperview];
    }];
}
- (void)webview{
    
    NSString *str  = @"http://mp.weixin.qq.com/s?__biz=MzAxODQwMTYxMA==&mid=502752513&idx=1&sn=e6212db8bb98fbda13cff66fafdcb520&scene=1&srcid=0607KB0xxnsxbvR8S3FBpcpx&from=groupmessage&isappinstalled=0#wechat_redirect";
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:str]];
    
    UIWebView *webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 15)];
    
    webview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:webview];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    [webview loadRequest:request];
    
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}

-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)createUI{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    
    [self.view addSubview:view];
    
    
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/2-WIDTH/8, 110*MYHEIGHT, WIDTH/4, WIDTH/4)];
    image.image = [UIImage imageNamed:@"Icon-120"];
    image.layer.cornerRadius = 10;
    [self.view addSubview:image];
    
    UILabel *titlelab = [[UILabel alloc]initWithFrame:CGRectMake(20, 120*MYHEIGHT+WIDTH/4,WIDTH-40, 100)];
    titlelab.numberOfLines = 0;
    titlelab.text = @"拇指营销\r\r朋友圈免费打广告的营销利器，商家的福音！";
    titlelab.textAlignment = NSTextAlignmentCenter;
    titlelab.textColor = UIColorFromRGB(MYColor);
    titlelab.font = [UIFont fontWithName:@"Heiti SC-Bold" size:15];
    [self.view addSubview:titlelab];

    
    UILabel *TextLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, HEIGHT - HEIGHT*5/12, WIDTH - 40, HEIGHT / 4)];
    TextLabel.text = @"【联系我们】\n\n  企业网址: http://www.wangdao.com \n\n  客服热线:0531-66663324 \n\n  售前咨询:15069073600";
    TextLabel.numberOfLines = 0;
    TextLabel.font = [UIFont systemFontOfSize:14 *MYWIDTH];
    TextLabel.textColor = UIColorFromRGB(MYRed);
    [view addSubview:TextLabel];
    
    
    UIButton *but = [[UIButton alloc]initWithFrame:CGRectMake(80, HEIGHT - HEIGHT*5/12 + HEIGHT / 8, 150, 30)];
    [but addTarget:self action:@selector(photobut) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:but];
    
    
    UIButton *but1 = [[UIButton alloc]initWithFrame:CGRectMake(80, HEIGHT - HEIGHT*5/12 + HEIGHT*3/16, 150, 30)];
    [but1 addTarget:self action:@selector(photobut1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:but1];
   }
- (void)photobut{
    [self phontbut:@"0531-66663324"];

}
- (void)photobut1{
    [self phontbut:@"15069073600"];
    
}
- (void)phontbut:(NSString *)phontNum{
    UIWebView *callWebView = [[UIWebView alloc] init];
    
    NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phontNum]];
    
    [callWebView loadRequest:[NSURLRequest requestWithURL:telURL]];
    [self.view addSubview:callWebView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
